package cn.hznc.domain.entity;

import cn.hznc.domain.entity.common.BaseEntity;
import cn.hznc.vo.CraftParamVo;
import cn.hznc.vo.InCraftVo;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 加工工单表
 *
 * @Author Administrator
 * @Date 2023/3/20 8:39
 */
@Getter
@Setter
@Table(name = "t_order")
@TableName(value = "t_order")
public class OrderEntity extends BaseEntity {

    @Column(name = "id",type = MySqlTypeConstant.INT,length = 11,isKey = true,isAutoIncrement = true)
    @TableId(type = IdType.AUTO)
    private Integer id;


    /**
     * 生产订单号
     */
    @Column(name = "task_id", type = MySqlTypeConstant.VARCHAR, length = 200)
    @TableField("task_id")
    private String taskId;

    /**
     * 工单产品名称
     */
    @Column(name = "production_name", type = MySqlTypeConstant.VARCHAR, length = 200)
    @TableField("production_name")
    private String productionName;


    /**
     * 优先级
     */
    @Column(name = "priority", type = MySqlTypeConstant.VARCHAR, length = 10)
    private String priority;

    /**
     * 工单产品型号
     */
    @Column(name = "production_num", type = MySqlTypeConstant.VARCHAR, length = 200)
    @TableField("production_num")
    private String productionNum;

    /**
     * 净重
     */
    @Column(name = "heavy", type = MySqlTypeConstant.DECIMAL , length = 14)
    @TableField("heavy")
    private BigDecimal heavy;


    /**
     * 计划数量
     */
    @Column(name = "plan_number", type = MySqlTypeConstant.INT, length = 11)
    @TableField("plan_number")
    private Integer planNumber;

    /**
     * 投入数量
     */
    @Column(name = "real_number", type = MySqlTypeConstant.INT, length = 11)
    @TableField("real_number")
    private Integer realNumber;

    /**
     * 公司图号
     */
    @Column(name = "figure_no", type = MySqlTypeConstant.VARCHAR, length = 200)
    @TableField(value = "figure_no")
    private String figureNo;


    /**
     * 库位
     */
    @Column(name = "storage_space", type = MySqlTypeConstant.VARCHAR, length = 50)
    @TableField(value = "storage_space")
    private String storageSpace;

    /**
     * 物料编码
     */
    @Column(name = "material_no", type = MySqlTypeConstant.VARCHAR, length = 200)
    @TableField(value = "material_no")
    private String materialNo;


    /**
     * 版本
     */
    @Column(name = "version", type = MySqlTypeConstant.INT, length = 11)
    private Integer version;

    /**
     * 修改日期
     */
    @Column(name = "modify_time", type = MySqlTypeConstant.DATETIME, length = 0)
    @TableField("modify_time")

    private Date modifyTime;

    /**
     * 订单创建日期
     */
    @Column(name = "create_time", type = MySqlTypeConstant.DATETIME, length = 0)
    @TableField("create_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 交付日期
     */
    @Column(name = "finish_time", type = MySqlTypeConstant.DATETIME, length = 0)
    @TableField("finish_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date finishTime;

    /**
     * 备注
     */
    @Column(name = "bz", type = MySqlTypeConstant.VARCHAR, length = 255)
    @TableField(value = "bz")
    private String bz;

    /**
     * 工单编辑状态
     */
    @Column(name = "status", type = MySqlTypeConstant.TINYINT)
    @TableField(value = "status")
    private Integer status;

    /**
     * 图号图片
     */
    @Column(name = "figure_no_image", type = MySqlTypeConstant.TINYINT)
    @TableField(value = "figure_no_image")
    private String figureNoImage;

    /**
     * 工单加工状态
     */
    @Column(name = "order_status", type = MySqlTypeConstant.INT, length = 11)
    @TableField("order_status")
    private Integer orderStatus;

    /**
     * 订单状态（对接工艺质量管理系统）
     */
    @Column(name = "abutment_status", type = MySqlTypeConstant.INT, length = 11)
    @TableField("abutment_status")
    private Integer abutmentStatus;

    /**
     * 下达日期（对接工艺质量管理系统）
     */
    @Column(name = "release_time", type = MySqlTypeConstant.DATETIME)
    @TableField("release_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date releaseTime;

    /**
     * 在制工序(对接工艺质量管理系统）
     */
    @TableField(exist = false)
    private List<InCraftVo> inCrafts;

    /**
     * 在制工序(对接工艺质量管理系统）
     */
    @TableField(exist = false)
    private List<CraftParamVo> craftParamVos;

    @TableField(exist = false)
    private Double totalCost = 0.0;

    @TableField(exist = false)
    private Double totalTime = 0.0;

    /**
     * 工序停滞时间
     */
    @TableField(exist = false)
    private Long standTime;

    /**
     * 工序转入时间
     */
    @TableField(exist = false)
    private Long inboundTime;

    /**
     * 工序周期
     */
    @TableField(exist = false)
    private Long cycleTime;

    /**
     * 在制工序名称
     */
    @TableField(exist = false)
    private String inCraftName;

    /**
     * 在制工序名称
     */
    @Column(name = "sort_priority", type = MySqlTypeConstant.INT , length = 5)
    @TableField("sort_priority")
    private Integer sortPriority;

    /**
     * 产品图号冗余字段
     */
    @Column(name = "figure_no_reload",type = MySqlTypeConstant.VARCHAR, length = 200)
    @TableField(value = "figure_no_reload")
    private String figureNoReload;

    /**
     * 总成本冗余字段
     */
    @TableField(exist = false)
    private Double totalPrice;

    /**
     * 机床冗余字段
     */
    @TableField(exist = false)
    private List<String> warehouseNames;


    /**
     * 保证taskId唯一性 根据taskId去重
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        OrderEntity that = (OrderEntity) o;

        return taskId.equals(that.taskId);
    }

    @Override
    public int hashCode() {
        return taskId.hashCode();
    }
}
